package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VendoutContract;
import com.lkd.emq.Topic;
import com.lkd.service.ChannelService;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.apache.logging.log4j.util.Strings;

import javax.annotation.Resource;
import java.io.IOException;

@Topic(TopicConfig.VMS_VENDOUT_TOPIC)
public class VendOutHandler implements MsgHandler {
    @Resource
    private ChannelService channelService;

    /**
     * 监听出货请求
     *
     * @param jsonMsg
     * @throws IOException
     */
    @Override
    public void process(String jsonMsg) throws IOException {
        //解析协议
        VendoutContract contract = JsonUtil.getByJson(jsonMsg, VendoutContract.class);
        if (Strings.isEmpty(contract.getInnerCode()) && contract.getInnerCode() == null) {
            return;
        }
        //处理出货,更新库存
        channelService.updateStock(contract);
    }
}
